using System;
using System.Collections.Generic;
using System.Text;
using TVProgram.Base;
using System.Net;
using System.IO;
using System.Globalization;

namespace TVProgram.Channels
{
    class S24h : BaseChannel
    {
        public S24h(DateTime CurDay, string channel)
        {
            this._name = channel;
            this._date = CurDay;
            string Day = Convert.ToString(this._date.Day);
            string Month = Convert.ToString(this._date.Month);
            string Year = Convert.ToString(this._date.Year);
            this._url = "http://hcm.24h.com.vn/ttcb/truyenhinh/truyenhinh.php?date=" + Year + "-" + Month + "-" + Day + "&channel=" + channel;
            //this._url = "http://www.htv.com.vn/chuongtrinh/default.asp?channel_id=" + channel + "&date=" + Day + "-" + Month + "-" + Year + "#lps";
        }

        public override void GetTextFromHtml(string html)
        {

            string stra = "style=\"padding-left:7px;\" class=\"truyenhinh";
            string str1 = "\">";
            string str2 = "&nbsp";
            int curIndex = 0;

            while (true)
            {
                curIndex = html.IndexOf(stra, curIndex);
                if (curIndex == -1)
                    break;
                curIndex = html.IndexOf(str1, curIndex);
                int startIndex = curIndex + str1.Length;

                curIndex = html.IndexOf(str2, startIndex);
                if (curIndex == -1)
                    break;
                int endIndex = curIndex;

                string StrTime = html.Substring(startIndex, endIndex - startIndex);
                string strHour = StrTime.Substring(0, 2);
                int Hour = Convert.ToInt32(strHour);
                if (Hour > 23)
                    break;
                curIndex += str2.Length;

                string str3 = "&nbsp;";
                string str4 = "</td>";

                curIndex = html.IndexOf(str3, curIndex);
                if (curIndex == -1)
                    break;
                startIndex = curIndex + str3.Length;

                curIndex = html.IndexOf(str4, startIndex);
                if (curIndex == -1)
                    break;
                endIndex = curIndex;
                curIndex += str4.Length;
                string StrTitle = html.Substring(startIndex, endIndex - startIndex);

                ProgramItem item = new ProgramItem();
                item.StartTime = item.GetDateTimeFromString(StrTime);
                item.Content = StrTitle;
                this._items.Add(item);
            }

        }
    }
}

